package com.util;

public class StringUtil {

	public static boolean isNumber(String str) {
		try {
			Long.parseLong(str);
			return true;
		} catch (Exception e) {

		}
		return false;
	}

	public static boolean isNull(String str) {
		if (str == null || str.trim().length() == 0 || "undefined".equals(str) || "null".equals(str)) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * 元转换成分
	 * @return
	 */
	public static String getMoney(String amount) {
		if(amount==null){
			return "";
		}
		// 金额转化为分为单位
		String currency =  amount.replaceAll("\\$|\\￥|\\,", "");  //处理包含, ￥ 或者$的金额
		int index = currency.indexOf(".");
		int length = currency.length();
		Long amLong = 0l;
		if(index == -1){
			amLong = Long.valueOf(currency+"00");
		}else if(length - index >= 3){
			amLong = Long.valueOf((currency.substring(0, index+3)).replace(".", ""));
		}else if(length - index == 2){
			amLong = Long.valueOf((currency.substring(0, index+2)).replace(".", "")+0);
		}else{
			amLong = Long.valueOf((currency.substring(0, index+1)).replace(".", "")+"00");
		}
		return amLong.toString();
	}

	public static boolean isNotNull(String str) {
		return !isNull(str);
	}

	/**
	 * 截取一键加群的href部分
	 * @param str
	 * @return
	 * 
	 */
	public static String getLianjie(String str) {
		if (isNotNull(str)) {

			if (str.contains("href")) {
				int start = str.indexOf("href=");
				int end = str.indexOf("><img");
				String sString = str.substring(start, end);
				String[] newString = sString.split("\"");
				str = newString[1];
			}
		}
		return str;
	}
}
